﻿using System.Collections;
using System.Collections.Generic;
using Library.WebControls.SimpleTreeView;

namespace Library.WebControls.SimpleFileExplorer {
	public class FileStructDatasource : List<IFileStruct>, ICollection<IFileStruct>, ICollection<ITreeViewDataItem>, ITreeViewDataSource {


		#region ICollection<ITreeViewDataItem> Members

		void ICollection<ITreeViewDataItem>.Add(ITreeViewDataItem item) {
			Add((IFileStruct)item);
		}

		void ICollection<ITreeViewDataItem>.Clear() {
			Clear();
		}

		bool ICollection<ITreeViewDataItem>.Contains(ITreeViewDataItem item) {
			return Contains((IFileStruct)item);
		}

		void ICollection<ITreeViewDataItem>.CopyTo(ITreeViewDataItem[] array, int arrayIndex) {
			CopyTo((IFileStruct[])array, arrayIndex);
		}

		int ICollection<ITreeViewDataItem>.Count {
			get { return Count; }
		}

		bool ICollection<ITreeViewDataItem>.IsReadOnly {
			get { return false; }
		}

		bool ICollection<ITreeViewDataItem>.Remove(ITreeViewDataItem item) {
			return Remove((IFileStruct)item);
		}

		#endregion

		#region IEnumerable<ITreeViewDataItem> Members

		IEnumerator<ITreeViewDataItem> IEnumerable<ITreeViewDataItem>.GetEnumerator() {
			return new Rator(GetEnumerator());
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}

		private struct Rator : IEnumerator<ITreeViewDataItem> {
			public Rator(IEnumerator<IFileStruct> file) {
				_file = file;
			}
			private readonly IEnumerator<IFileStruct> _file;
			public void Dispose() {
				_file.Dispose();
			}

			public bool MoveNext() {
				return _file.MoveNext();
			}

			public void Reset() {
				_file.Reset();
			}

			public ITreeViewDataItem Current {
				get { return _file.Current; }
			}

			object IEnumerator.Current {
				get { return Current; }
			}
		}
		#endregion
	}


}
